package com.example.tool.service.selforder;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.tool.bean.business.wdt.SelfOrderDO;
import com.example.tool.bean.business.wdt.SelfOrderWithDetailDO;
import com.example.tool.mapper.SelfOrderMapper;
import com.example.tool.mapper.SelfOrderWithDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Qualifier("selfOrderService")
public class SelfOrderServiceImpl extends ServiceImpl<SelfOrderMapper, SelfOrderDO> implements SelfOrderService {
    @Autowired
    SelfOrderMapper selfOrderMapper;
    @Autowired
    SelfOrderWithDetailMapper selfOrderWithDetailMapper;

    @Async
    @Override
    public void storageSelfOrder(List<SelfOrderDO>data) {
        for (SelfOrderDO selfOrder:data){
        selfOrderMapper.insert(selfOrder);
           for(SelfOrderWithDetailDO detailDO:selfOrder.getDetailList()){
               selfOrderWithDetailMapper.insert(detailDO);
           }
        }
    }

    @Override
    public List<SelfOrderDO> findSelfOrders(List<String>  searchTimes, List<Integer> tradeStatus) {
        String startSearchTime = searchTimes.get(0);
        String endSearchTime = searchTimes.get(1);
        QueryWrapper<SelfOrderDO> estimateConsignTime = new QueryWrapper<SelfOrderDO>().between("estimate_consign_time", startSearchTime,endSearchTime).in("trade_status",tradeStatus).orderByDesc("estimate_consign_time");
        return selfOrderMapper.selectList(estimateConsignTime);
    }





}
